package com.chis.jxc;

import com.chis.jxc.bean.*;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

import java.io.File;
import java.io.FileInputStream;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 
 * @Description 解析国家国家疫苗标准库
 * @Company zwx
 * @author wlj
 * @version 2020年01月04日
 */
public class ConvertBaseUtil {

    public static void main(String[] args) throws Exception {
        String xmlPath = "C:\\Users\\wlj\\Desktop\\1621447198967.xml";
        Map<String,VaccBean> vaccmap = new LinkedHashMap<>();
        VaccMainBean vaccMainBean = deal(xmlPath);
        for(VaccBean bean : vaccMainBean.getVaccBeanList()){
            vaccmap.put(bean.getGJYPBSM(),bean);
        }
        xmlPath = "C:\\Users\\wlj\\Desktop\\1621447202517.xml";
        vaccMainBean = deal(xmlPath);
        for(VaccBean bean : vaccMainBean.getVaccBeanList()){
            vaccmap.put(bean.getGJYPBSM(),bean);
        }
    
        for(String key : vaccmap.keySet()){
//            System.out.println(JSON.toJSONString(vaccmap.get(key)));
            VaccBean bean = vaccmap.get(key);
            StringBuilder sb = new StringBuilder("insert into TB_JXCGJ_VACCINE(            GJYPBSM,            YPTYMC,            YPYWMC,            " +
                    "YPSPMC,            YPBWM,            JX,            ZJGG,            BZGG,            BZZHB,            BZZHBDW,            " +
                    "YMYXQ,            JKYPZCZH,            JKYPZCZYXQ,            PZRQ,            JKYPPJH,            JKYPPJYXQ,            " +
                    "YPPZWH,            YPPZWHYXQ,            YWSYCJL,            YWSYJLDW,            ZXXSBZDYKYRFS,            " +
                    "GSMCZW,            GSMCYW,            GSDZZW,            GSDZYW,            GSGJHDQZW,           " +
                    " GSGJHDQEN,            SCCMCZW,            SCCMCYW,            SCCDZZW,            SCCDZEN,         " +
                    "   SCCGJHDQZW,            SCCGJHDQEN,            FBZCMC,            TYSHXYDMFBZC,            FBZCDZ,    " +
                    "        SFGJMYGHYM,            SCZT,            TYSHXYDMDLQY,            DLQYMC,            SCQYMC,          " +
                    "  TYSHXYDMSCQY,            YMSSXKCYRMC,            TYSHXYDMYMSSXKCYR,            ZJHYMSSXKCYR,            ZJLX,   " +
                    "         BZGGBS,TYSHXYDM,ISDEL)        values");
            sb.append("('").append(bean.getGJYPBSM()).append("',");
            sb.append("'").append(bean.getYPTYMC()).append("',");
            sb.append("'").append(bean.getYPYWMC()).append("',");
            sb.append("'").append(bean.getYPSPMC()).append("',");
            sb.append("'").append(bean.getYPBWM()).append("',");
            sb.append("'").append(bean.getJX()).append("',");
            sb.append("'").append(bean.getZJGG()).append("',");
            sb.append("'").append(bean.getBZGG()).append("',");
            sb.append("'").append(bean.getBZZHB()).append("',");
            sb.append("'").append(bean.getBZZHBDW()).append("',");
            sb.append("'").append(bean.getYMYXQ()).append("',");
            sb.append("'").append(bean.getJKYPZCZH()).append("',");
            sb.append("'").append(bean.getJKYPZCZYXQ()).append("',");
            sb.append("'").append(bean.getPZRQ()).append("',");
            sb.append("'").append(bean.getJKYPPJH()).append("',");
            sb.append("'").append(bean.getJKYPPJYXQ()).append("',");
            sb.append("'").append(bean.getYPPZWH()).append("',");
            sb.append("'").append(bean.getYPPZWHYXQ()).append("',");
            sb.append("'").append(bean.getYWSYCJL()).append("',");
            sb.append("'").append(bean.getYWSYJLDW()).append("',");
            sb.append("'").append(bean.getZXXSBZDYKYRFS()).append("',");
            sb.append("'").append(bean.getGSMCZW()).append("',");
            sb.append("'").append(bean.getGSMCYW()).append("',");
            sb.append("'").append(bean.getGSDZZW()).append("',");
            sb.append("'").append(bean.getGSDZYW()).append("',");
            sb.append("'").append(bean.getGSGJHDQZW()).append("',");
            sb.append("'").append(bean.getGSGJHDQEN()).append("',");
            sb.append("'").append(bean.getSCCMCZW()).append("',");
            sb.append("'").append(bean.getSCCMCYW()).append("',");
            sb.append("'").append(bean.getSCCDZZW()).append("',");
            sb.append("'").append(bean.getSCCDZEN()).append("',");
            sb.append("'").append(bean.getSCCGJHDQZW()).append("',");
            sb.append("'").append(bean.getSCCGJHDQEN()).append("',");
            sb.append("'").append(bean.getFBZCMC()).append("',");
            sb.append("'").append(bean.getTYSHXYDMFBZC()).append("',");
            sb.append("'").append(bean.getFBZCDZ()).append("',");
            sb.append("'").append(bean.getSFGJMYGHYM()).append("',");
            sb.append("'").append(bean.getSCZT()).append("',");
            sb.append("'").append(bean.getTYSHXYDMDLQY()).append("',");
            sb.append("'").append(bean.getDLQYMC()).append("',");
            sb.append("'").append(bean.getSCQYMC()).append("',");
            sb.append("'").append(bean.getTYSHXYDMSCQY()).append("',");
            sb.append("'").append(bean.getYMSSXKCYRMC()).append("',");
            sb.append("'").append(bean.getTYSHXYDMYMSSXKCYR()).append("',");
            sb.append("'").append(bean.getZJHYMSSXKCYR()).append("',");
            sb.append("'").append(bean.getZJLX()).append("',");
            sb.append("'").append(bean.getBZGGBS()).append("',");
            sb.append("'").append(bean.getTYSHXYDM()).append("',");
            sb.append("'").append(bean.getISDEL()).append("');");
            System.out.println(sb.toString());
        }


    }

    public static VaccMainBean deal(String xmlPath) throws Exception {
        File file=new File(xmlPath);
        FileInputStream in=new FileInputStream(file);
        int size=in.available();
        byte[] buffer=new byte[size];
        in.read(buffer);
        in.close();
        String resultXml=new String(buffer,"utf-8");
        XStream xStream = new XStream(new DomDriver());
        xStream.alias("VTTSBasic",VaccMainBean.class);
        xStream.aliasField("dataset",VaccMainBean.class,"vaccBeanList");
        xStream.alias("data",VaccBean.class);
        xStream.aliasField("BASQXQS",VaccBean.class,"sublist");
        xStream.alias("BASQXQ",VaccsubBean.class);
        return (VaccMainBean)xStream.fromXML(resultXml);
    }

}
